package com.sos.controller;

import com.sos.model.entity.Notification;
import com.sos.model.vo.ResultVO;
import com.sos.service.NotificationService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/notifications")
@RequiredArgsConstructor
@Tag(name = "通知管理", description = "用户通知相关接口")
public class NotificationController {

    private final NotificationService notificationService;

    @PutMapping("/{notificationId}/read")
    @Operation(summary = "标记通知为已读", description = "将指定通知标记为已读")
    public ResultVO<?> markNotificationAsRead(@PathVariable Long notificationId) {
        notificationService.markAsRead(notificationId);
        return ResultVO.success();
    }

    @GetMapping("/history")
    @Operation(summary = "获取历史通知", description = "获取指定时间范围内的历史通知")
    public ResultVO<List<Notification>> getHistoryNotifications(
            @RequestParam(required = false) Long sinceId,
            @RequestParam(defaultValue = "20") Integer limit) {
        return ResultVO.success(notificationService.getHistoryNotifications(sinceId, limit));
    }
}